package com.bookstore.mapper;

import com.bookstore.domain.Address;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressMapper {
    @Select("select * from address where uid=#{uid}")
    public List<Address> findByUid(@Param("uid") Integer buyers);

    @Select("select * from address where addressId=#{addressId}")
    public List<Address> findByAddressId(@Param("addressId") Integer addressId);

    /*

SELECT * FROM b_order o,address a
WHERE o.buyers=a.uid AND o.orderId =1 AND o.addressId=a.addressId
     */
    @Select("select * from b_order o,address a where o.buyers=a.uid and o.orderId=#{uid} and o.addressId=a.addressId")
    Address findAllByUidAndOrderId(@Param("orderId") String orderId, @Param("uid") Integer uid);

    @Insert("INSERT INTO address values(null,#{uid},#{address},#{phone},#{name})")
    int addAddress(Address address);

    @Select("select * from address where addressId=#{addressId}")
    Address getOneById(Integer addressId);

    @Update("update address set name=#{name}, address=#{address}, phone=#{phone} where addressId=#{addressId}")
    int upAddress(Address address);

    @Delete("delete from address where addressId=#{addressId}")
    int delAddress(Integer addressId);
        @Delete("delete from address where uid=#{uid}")
    int delAddresses(@Param("uid") Integer uid);
}
